package com.yylending.las.repay;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yylending.las.Global;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

import java.util.List;

/**
 * M :借款详情 && 还款首页共用该接口
 * Created by laixj on 2017/5/25.
 * Copyright ©2016 www.yylending.com. All Rights Reserved.
 */
public class LoanDetailModel extends Model {
	private static final String TAG = LoanDetailModel.class.getSimpleName();

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		return service.getLoanDetail(Global.LOGIN_TOKEN, (RequestParams) params);
	}

	@Override
	public void onNext(Object entity) {
		LoanDetailResult result = cast(entity);
		EventAgent.post(result);
	}

	private interface Service {

		@POST("server/loan/getLoanDetail")
		Observable<LoanDetailResult> getLoanDetail(@Header("token") String token, @Body RequestParams params);
	}

	static class RequestParams {
		public String loanNo = "";
		public String type = "";
	}

	static class LoanDetailResult extends BaseResultEntity<List<LoanDetail>> {
	}

	public static class LoanDetail {
		/**
		 * 本期应还（待还&还款中 有值）
		 */
		public String repayAmount;
		/**
		 * 还款日
		 */
		public String repayDate;
		/**
		 * 待还贷款期数
		 */
		public String repayTerm;
		/**
		 * 总期数
		 */
		public String loanTerm;
		/**
		 * 还款银行卡号（只有尾号）
		 */
		public String repayCard;
		/**
		 * 还款状态 0：「无借款」1:「已还清」 2:「已还款」3:「逾期」4:「还款处理中」5:「待还」
		 */
		public String repayStatus;
		/**
		 * 放款日期
		 */
		public String loanDate;
		/**
		 * 放款金额
		 */
		public String loanAmount;
		/**
		 * 已还清金额(「已还」 有值)
		 */
		public String paidAmount;
		/**
		 * 还款银行名称
		 */
		public String repayBank;
		/**
		 * 借据号
		 */
		public String loanNo;

	}

}
